import Vue from 'vue';
import Component from 'vue-class-component';
import store from '@/store';

@Component
export class TagHelper extends Vue {
  get tags() {
    return store.state.tagList;
  }

  created() {
    this.$store.dispatch('getTagList');
  }

  createTag() {
    const name: string | null = window.prompt('请输入标签名:');
    if (name === null) return;
    if (!(name && name.trim())) {
      alert('标签名不能为空!');
      return;
    }
    this.$store.dispatch('saveTags', {name, isAdd: true});
  }
}

export default TagHelper;
